<div id="user_list">
    <div class="modal-header">
        <span class="modal-title">{:lang('v_user')}</span>
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span></button>
    </div>
    <!--内容 开始-->
    <div class="p-2">
        <form name="form_checksearch" id="form_checksearch" class="row">
            <input type="hidden" name="lang" id="lang" value="{$lang}">
            <input type="hidden" name="signid" value="1">
            <div class="col-md-4">
                <div class="row">
                    <div class="btn btn-success mb-2" id="user_check_close"><i class="fa fa-check-circle"></i> {:lang('shopv_confirm')} {:lang('v_select')}</div>
                </div>
            </div>
            <div class="col-md-8 pr-2">
                <div class="input-group">
                    <input name="keyword" id="keyword" placeholder="{:lang('v_quickfind')}" type="text" class="form-control">
                    <span class="input-group-append">
                        <button type="button" id="search_user" class="btn btn-success"><i class="fa fa-search mr-1"></i>{:lang('v_search')}</button>
                    </span>
                </div>
            </div>
        </form>
    </div>
    <div class="p-2">
        <table class="table table-striped table-bordered table-hover mb-0">
            <tr>
                <td><span class="checkbox-toggle"><i class="fa fa-square-o fa-lg mr-2"></i>ID</span></td>
                <td class="hidden-xs">{:lang('v_authgroup')}</td>
                <td class="hidden-xs">{:lang('v_user')}</td>
            </tr>
            <form name="form_check" id="form_check">
                {volist name="list" id="rs"}
                    <tr>
                        <td>
                            <label>
                                <input type="checkbox" name="selectid[]" class="selectid" value="{$rs.id}" {if in_array($rs.id,$user_json)}checked="checked"{/if} />
                                <span class="hidden-xs"> {$rs.id}</span>
                            </label>
                        </td>
                        <td class="hidden-xs">{$rs.title}</td>
                        <td class="hidden-xs"><img src="{$rs.avatar}" height="30" class="img-rounded mr-2" onerror="this.src='{:config('template.skin')}/img/nopic.png'" />{$rs.nickname}</td>
                    </tr>
                {/volist}
                <tr>
                    <td colspan="3">
                        <div class="w-100 mt-2">
                            <div class="float-left">{$list->render()|raw}</div>
                            <div class="float-left">{:lang('v_total')} {$lastPage} {:lang('v_page')} {$total} {:lang('v_records')}</div>
                        </div>
                    </td>
                </tr>
            </form>
        </table>
    </div>
    <!--内容 结束-->
    <script src="{:config('template.skin')}/icheck/icheck.min.js"></script>
    <script type="text/javascript">
    //翻页
    $("#user_list").delegate(".pagination a","click",function(){
        $.get(this.href,function(html){
            $("#user_list").replaceWith(html);
        });
        return false;
    });
    //搜索
    $('#search_user').click(function(){
        var href = '{:url('/user/index')}?lang='+$('#lang').val()+'&keyword='+$('#keyword').val();
        $.get(href,function(html){
            $("#user_list").replaceWith(html);
        });
    });
    //根据cookie设置复选框是否选中
    var cookie_val = $.cookie('bmkj_admin_user');
    //cookie存在
    if(cookie_val != null){
        //cookie转数组
        cookie_val_arr = cookie_val.split(':');
        //获取列表复选框的值
        $('input:checkbox').each(function (i,val){
            if(cookie_val_arr.includes($(this).val())){
                $(this).attr('checked','checked');
            }
        });
    }
    //单击复选框，设置选中值的cookie
    $('input[type="checkbox"]').click(function(){
        var cookie_val = $.cookie('bmkj_admin_user');
        var this_val = $(this).val();
        //选中
        if($(this).prop("checked")){
            //cookie存在
            if(cookie_val != null && cookie_val.length > 0){
                $.cookie('bmkj_admin_user',cookie_val+':'+this_val,{expires:1,path:'/'});
            }else{
                $.cookie('bmkj_admin_user',this_val,{expires:1,path:'/'});
            }
        }else{
            if(cookie_val != null){
                var cookie_val_arr = cookie_val.split(':');
                //如果cookie数组包含该复选框的值
                if(cookie_val_arr.includes($(this).val())){
                    //从cookie数组中删除该值
                    cookie_val_arr.splice($.inArray($(this).val(),cookie_val_arr),1);
                    var cookie_str = '';
                    $.each(cookie_val_arr,function(i,val){
                        if(i == 0){
                            cookie_str = val;
                        }else{
                            cookie_str += ':'+val;
                        }
                    });
                    $.cookie('bmkj_admin_user',cookie_str,{expires:1,path:'/'});
                }
            }
        }
    });
    //全选/反选，设置选中值的cookie
    $(".checkbox-toggle").click(function () {
        //全选/反选
        var clicks = $(this).data('clicks');
        if (clicks) {
            $(".box-body input[name='selectid[]']").iCheck("uncheck");
            $(".fa", this).removeClass("fa-check-square-o").addClass('fa-square-o');
        } else {
            $(".box-body input[name='selectid[]']").iCheck("check");
            $(".fa", this).removeClass("fa-square-o").addClass('fa-check-square-o');
        }
        $(this).data("clicks", !clicks);
        //全选中，设置cookie
        $("input[name='selectid[]']:checked").each(function(){
            var cookie_val = $.cookie('bmkj_admin_user');
            //cookie存在
            if(cookie_val != null){
                var cookie_val_arr = cookie_val.split(':');
                if(!cookie_val_arr.includes($(this).val())){
                    $.cookie('bmkj_admin_user',cookie_val+':'+$(this).val(),{expires:1,path:'/'});
                }
            }else{
                $.cookie('bmkj_admin_user',$(this).val(),{expires:1,path:'/'});
            }
        });
        //全未选，设置cookie
        $("input[name='selectid[]']:not(:checked)").each(function(){
            var cookie_val = $.cookie('bmkj_admin_user');
                //cookie存在
                if(cookie_val != null){
                    var cookie_val_arr = cookie_val.split(':');
                    //如果cookie数组包含该复选框的值
                    if(cookie_val_arr.includes($(this).val())){
                        //从cookie数组中删除该值
                        cookie_val_arr.splice($.inArray($(this).val(),cookie_val_arr),1);
                        var cookie_str = '';
                        $.each(cookie_val_arr,function(i,val){
                            if(i == 0){
                                cookie_str = val;
                            }else{
                                cookie_str += ':'+val;
                            }
                        });
                        $.cookie('bmkj_admin_user',cookie_str,{expires:1,path:'/'});
                    }
                }
        });
    });
    //参与会员：关闭窗口
    $('#user_check_close').click(function(){
        var idStr = $.cookie('bmkj_admin_user');
        var user_json_str = '{$user_json_str}';
        $.ajax({
            type: 'POST',
            url: '/api/coupon/userlist.html',
            dataType: 'json',
            data: {id_str:idStr,user_json:user_json_str},
            success: function(data){
                var rs = JSON.parse(data);
                var html = '';
                if(rs.length > 0){
                    html = '<div class="col-md-12 p-1 bold text-0">{:lang('v_belong')} {:lang('v_user')}：</div>'
                    for(var i=0;i<rs.length;i++){
                        if(rs[i]['avatar'].length > 0){
                            avatar = rs[i]['avatar'];
                        }else{
                            avatar = '{:config('template.skin')}/img/nopic.png';
                        }
                        html += '<label class="col-md-2 p-1 mb-2 table-bordered cursor"><img src="'+avatar+'" height="30" class="img-rounded" /><input name="user_json[]" type="checkbox" value="'+rs[i]['id']+'" checked="checked" class="media-middle mt-1 mb-2">'+rs[i]['id']+'、'+rs[i]['nickname'].substr(0,8)+'</label>';
                    }
                }
                $('#userrs_list').html(html);
            }
        });
        $("#modal").modal("hide");
    });
    </script>
</div>